#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <memshr.h>
#include "tapdisk.h"
#include "blktap2.h"
params = NULL;
- while ((c = getopt(argc, argv, "n:h")) != -1) {
+ while ((c = getopt(argc, argv, "n:s:h")) != -1) {
switch (c) {
case 'n':
params = optarg;
break;
case 'h':
usage(argv[0], 0);
+ break;
+ case 's':
+ memshr_set_domid(atoi(optarg));
+ break;
default:
usage(argv[0], EINVAL);
}
# Should be at least 2KB per MB of domain memory, plus a few MB per vcpu.
# shadow_memory = 8
+# Whether to transparently share this domain's memory with other domains.
+# default = 0
+# memory_sharing = 0
+
# A name for your domain. All domains must have different names.
name = "ExampleHVMDomain"
#include "memshr-priv.h"
#include "shm.h"
+typedef struct {
+ int enabled;
+ domid_t domid;
+} memshr_vbd_info_t;
+
+memshr_vbd_info_t vbd_info = {0, DOMID_INVALID};
typedef struct {
struct shared_memshr_info *shared_info;
#define SHARED_INFO (memshr.shared_info)
+void memshr_set_domid(int domid)
+{
+ vbd_info.domid = domid;
+}
+
void memshr_daemon_initialize(void)
{
void *shm_base_addr;
DPRINTF("Failed to open blockshr_hash.\n");
return;
}
+
+ if(vbd_info.domid == DOMID_INVALID)
+ return;
+
+ vbd_info.enabled = 1;
}
typedef uint64_t xen_mfn_t;
+extern void memshr_set_domid(int domid);
extern void memshr_daemon_initialize(void);
extern void memshr_vbd_initialize(void);
return zero;
}
+static PyObject *pyxc_dom_set_memshr(XcObject *self, PyObject *args)
+{
+ uint32_t dom;
+ int enable;
+
+ if (!PyArg_ParseTuple(args, "ii", &dom, &enable))
+ return NULL;
+
+ if (xc_memshr_control(self->xc_handle, dom, enable) != 0)
+ return pyxc_error_to_exception();
+
+ Py_INCREF(zero);
+ return zero;
+}
+
+
static PyMethodDef pyxc_methods[] = {
{ "handle",
(PyCFunction)pyxc_handle,
" auth [int]: 0|1 .\n"
"Returns: [int] 0 on success; exception on error.\n" },
+ { "dom_set_memshr",
+ (PyCFunction)pyxc_dom_set_memshr,
+ METH_VARARGS, "\n"
+ "Enable/disable memory sharing for the domain.\n"
+ " dom [int]: Domain identifier.\n"
+ " enable [int,0|1]: Disable or enable?\n"
+ "Returns: [int] 0 on success; -1 on error.\n" },
+
{ NULL, NULL, 0, NULL }
};
'suppress_spurious_page_faults': bool0,
's3_integrity' : int,
'superpages' : int,
+ 'memory_sharing': int,
}
# List of legacy configuration keys that have no equivalent in the
dict.__init__(self)
self.update(self._defaults())
-
+
if filename:
try:
sxp_obj = sxp.parse(open(filename,'r'))
'shadow_memory': 0,
'memory_static_max': 0,
'memory_dynamic_max': 0,
+ 'memory_sharing': 0,
'devices': {},
'on_xend_start': 'ignore',
'on_xend_stop': 'ignore',
if not self["memory_static_max"] > 0:
raise XendConfigError("memory_static_max must be greater " \
"than zero")
+ if self["memory_sharing"] and not self.is_hvm():
+ raise XendConfigError("memory_sharing can only be enabled " \
+ "for HVM domains")
+ if self["memory_sharing"] and not self.is_hap():
+ raise XendConfigError("memory_sharing can only be enabled " \
+ "for HAP enabled boxes")
def _actions_sanity_check(self):
for event in ['shutdown', 'reboot', 'crash']:
val = sxp.child_value(image_sxp, 'superpages')
if val is not None:
self['superpages'] = val
+
+ val = sxp.child_value(image_sxp, 'memory_sharing')
+ if val is not None:
+ self['memory_sharing'] = val
for key in XENAPI_PLATFORM_CFG_TYPES.keys():
val = sxp.child_value(image_sxp, key, None)
ostype = None
superpages = 0
+ memory_sharing = 0
def __init__(self, vm, vmConfig):
self.vm = vm
self.apic = int(vmConfig['platform'].get('apic', 0))
self.acpi = int(vmConfig['platform'].get('acpi', 0))
self.guest_os_type = vmConfig['platform'].get('guest_os_type')
+ self.memory_sharing = int(vmConfig['memory_sharing'])
+ xc.dom_set_memshr(self.vm.getDomid(), self.memory_sharing)
# Return a list of cmd line args to the device models based on the
self.deviceClass = 'tap2'
return devid
- cmd = [ TAPDISK_BINARY, '-n', '%s:%s' % (params, file) ]
+ if self.vm.image.memory_sharing:
+ cmd = [ TAPDISK_BINARY, '-n', '%s:%s' % (params, file), '-s', '%d' % self.vm.getDomid() ]
+ else:
+ cmd = [ TAPDISK_BINARY, '-n', '%s:%s' % (params, file) ]
(rc,stdout,stderr) = doexec(cmd)
if rc != 0:
fn=set_int, default=0,
use="Domain shadow memory in MB.")
+gopts.var('memory_sharing', val='no|yes',
+ fn=set_bool, default=0,
+ use="Should memory be shared?")
+
gopts.var('cpu', val='CPU',
fn=set_int, default=None,
use="CPU to run the VCPU0 on.")
'usb', 'usbdevice',
'vcpus', 'vnc', 'vncconsole', 'vncdisplay', 'vnclisten',
'vncunused', 'viridian', 'vpt_align',
- 'xauthority', 'xen_extended_power_mgmt', 'xen_platform_pci' ]
+ 'xauthority', 'xen_extended_power_mgmt', 'xen_platform_pci',
+ 'memory_sharing' ]
for a in args:
if a in vals.__dict__ and vals.__dict__[a] is not None: